package com.caissa.framework.starter.autoconfigure.container;

import lombok.extern.slf4j.Slf4j;
import org.apache.coyote.http11.Http11NioProtocol;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;

@Slf4j
public class CustomContainer implements
        WebServerFactoryCustomizer<TomcatServletWebServerFactory> {

    @Override
    public void customize(TomcatServletWebServerFactory factory) {
        factory.addConnectorCustomizers(connector -> {
            Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
            protocol.setKeepAliveTimeout(8 * 60 * 60 * 1000);

            log.info("keepAliveTimeout = " + protocol.getKeepAliveTimeout());//默认60s
            log.info("useKeepAliveResponseHeader = " + protocol.getUseKeepAliveResponseHeader());//true
            log.info("maxConnections = " + protocol.getMaxConnections());//8192
            log.info("maxThreads = " + protocol.getMaxThreads());//200
            log.info("acceptCount = " + protocol.getAcceptCount());//100
            log.info("maxKeepAliveRequests = " + protocol.getMaxKeepAliveRequests());//100
        });
    }
}

